# _*_ coding : utf-8 _*_
# @Time : 2023/3/15 0015 16:18
# @Author : 菜鸟王小二
# @File : 13_urllib_微博的cookie
# @Project : python爬虫

import urllib.request
import urllib.parse

url = 'https://weibo.com/ajax/profile/detail?'
data = {
    'uid': 7826642084
}
url = url + urllib.parse.urlencode(data)
headers = {
    # ':authority':'weibo.com',
    # ':method':'GET',
    # ':path':'/ajax/statuses/mymblog?uid=7826642084&page=1&feature=0',
    # ':scheme':'https',
    'accept':'application/json, text/plain, */*',
    # 'accept-encoding':'gzip, deflate, br',
    'accept-language':'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'client-version':'v2.40.2',
    'cookie':'SINAGLOBAL=4108694713487.808.1661665293634; XSRF-TOKEN=AOlNgf4nKvCJbuLplKTMsqz7; PC_TOKEN=cda14f4a4d; login_sid_t=bdf358ba10c7fc9ea4c18d4f5b3396b0; cross_origin_proto=SSL; _s_tentry=weibo.com; Apache=1824191073831.054.1678867833506; ULV=1678867833510:2:1:1:1824191073831.054.1678867833506:1661665293726; wb_view_log=1920*10801; appkey=; SSOLoginState=1678868149; SUB=_2A25JFQ7lDeRhGeFG6VQX9CzMwziIHXVqY2ctrDV8PUNbmtANLVrlkW9NefoaCFILwP_nXkZhMk9xIOk7fJAV3H57; SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9WWgh6WC9npQVmoPcxiT2kwv5JpX5KzhUgL.FoMReoqcShz71hB2dJLoIp7LxKML1KBLBKnLxKqL1hnLBoMR1hqRehe4eoeE; ALF=1710404149; WBPSESS=c_ZolZj3qpTVCQDSocwqgKkNqB2-XhAj1matUp_7kv6CBVFnT-ArqszIJVCiaOFE212cRynEwOfJ_L5xxy0EWY_fEa8MhAx1mKHE1L-KFVg0qVFEWyWL9JnimKGV9T233EIPbs42_sF8JQ1hlBZDeQ==',
    'referer':'https://weibo.com/u/7826642084',
    'sec-ch-ua':'"Chromium";v="110", "Not A(Brand";v="24", "Microsoft Edge";v="110"',
    'sec-ch-ua-mobile':'?0',
    'sec-ch-ua-platform':'"Windows"',
    'sec-fetch-dest':'empty',
    'sec-fetch-mode':'cors',
    'sec-fetch-site':'same-origin',
    'server-version':'v2023.03.14.5',
    'traceparent':'00-c9aa93b9f0dc0b61e3996f428097c4b2-afcdd5a5285e6d92-01',
    'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63',
    'x-requested-with':'XMLHttpRequest',
    'x-xsrf-token':'AOlNgf4nKvCJbuLplKTMsqz7'
}

request = urllib.request.Request(url=url,headers=headers)
response = urllib.request.urlopen(request)
content = response.read().decode('utf-8')
print(content)

with open('weibbo.json','w',encoding='utf-8') as fp:
    fp.write(content)
